package com.omg.springboot_unit3.sys.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.omg.springboot_unit3.common.base.AdminBaseController;
import com.omg.springboot_unit3.common.utils.Result;
import com.omg.springboot_unit3.sys.dao.UserDao;
import com.omg.springboot_unit3.sys.domain.User;
import com.omg.springboot_unit3.sys.service.UserService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * InnoDB free: 10240 kB 前端控制器
 * </p>
 *
 * @author yuomg123
 * @since 2018-10-29
 */
@Controller
@RequestMapping("/user")
public class UserController extends AdminBaseController {
	@Autowired
	private UserService userService;
	
	@ResponseBody
	@RequestMapping("/list")
	public Result<Page<User>> getUserList() {
		Map<String,Object> map = new HashMap<String,Object>();
		Page<User> UserDO = userService.selectPage(getPage(User.class),userService.convertToEntityWrapper());
		map.put("userList", UserDO);
		return Result.ok(UserDO); 
	}
	
	@RequestMapping("/getUser")
	public String getUser() {
		Map<String,Object> map = new HashMap<String,Object>();
		User user = userService.selectById(1);
			map.put("userList", user);
		return "user/list";
	}
	
	@ResponseBody
	@RequestMapping("/getAll")
	public Map<String,Object> getAll() {
		Map<String,Object> map = new HashMap<String,Object>();
		Wrapper<User> wrapper = new EntityWrapper<User>();
		List<User> users = userService.selectList(wrapper);
		map.put("userList", users);
		return map;
	}
		
		
}

